package cc.shimeng.fucloud.tools;

import cc.shimeng.fucloud.entity.Student;
import cc.shimeng.fucloud.repository.StudentRepository;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Optional;

@Component
public class StudentTool {

    @Autowired
    private StudentRepository studentRepository;

    @Tool(description = "获取所有学生信息", name = "studentGetAll")
    public List<Student> getAll() {
        return studentRepository.findAll();
    }

    @Tool(description = "获取学生信息", name = "studentGet")
    public Optional<Student> get(@ToolParam(description = "学生ID") Integer id) {
        return studentRepository.findById(id);
    }

    @Tool(description = "创建学生信息", name = "studentSave")
    public Student save(Student student) {
        return studentRepository.save(student);
    }

    @Tool(description = "删除学生信息", name = "studentDelete")
    public void delete(@ToolParam(description = "学生ID") Integer id) {
        studentRepository.deleteById(id);
    }
}